var express = require('express');
var router = express.Router();
const schedulesApi = require("../api/schedules");

//通过放映厅查找座位
router.get('/Seats',async function (req, res, next) {
    const  {schedules}  = req.query;
    // console.log(schedules);
    const data = await schedulesApi.Seats({schedules});
    console.log(data);
    res.send(data);
})

// 获取排片列表
router.get("/", async function (req, res, next) {
    const { curPage, eachPage } = req.query;
    const data = await schedulesApi.get({ curPage, eachPage });
    res.send(data);
});

// 删除排片
router.delete("/delete/:_id", async function (req, res, next) {
    const _id = req.params;
    const status = await schedulesApi.deletes({ _id });
    res.send(status);
});

// 修改排片
router.put("/modify", async function (req, res, next) {
    const { _id, movieId, cinemasId, theaterId, showTime, price } = req.body;
    // const data = req.body;
    // console.log(data);
    const status = await schedulesApi.modify({ _id }, { movieId, cinemasId, theaterId, showTime, price });
    res.send(status);
});
// 新增排片
router.post('/addSchedules', async function (req, res, next) {
    const { movieId, cinemasId, theaterId, showTime, showDate, price } = req.body;
    console.log( movieId, cinemasId, theaterId, showTime, showDate, price);
    const status = await schedulesApi.create({ movieId, cinemasId, theaterId, showTime, showDate, price });
    res.send(status);
});


//根据影院查询排片

router.get('/search', async function (req, res, next) {
    const { cinemasId } = req.query;
    const data = await schedulesApi.searchone(cinemasId);
    res.send(data);
});

//根据电影查询排片

router.get('/searchmovies', async function (req, res, next) {
    const { movieId } = req.query;
    const data = await schedulesApi.searchmovies(movieId);
    res.send(data);
});

//searchscheId 排片查排片
router.get('/searchscheId', async function (req, res, next) {
    const { _id } = req.query;
    const data = await schedulesApi.searchid(_id);
    res.send(data);
});



module.exports = router;